package Filter;

import User.UserDTO;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

@WebFilter("/login/*")
public class Login_Filter implements Filter {

    public void destroy() {

    }
    public void init(FilterConfig config) throws ServletException {

    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;

        UserDTO LocalUser =(UserDTO) req.getSession().getAttribute("LocalUser");
        if(req.getRequestURI().contains("Login.jsp")||req.getRequestURI().contains("/login/dgut")||LocalUser!=null||req.getRequestURI().endsWith(".css")||req.getRequestURI().endsWith(".html")||req.getRequestURI().contains("js"))
        {
            chain.doFilter(req,res);
            return;
        }
        else{
            res.sendRedirect("https://cas.dgut.edu.cn?appid=javaee&state=STATE");

        }
    }
}